package com.turing.usdtpay.mvp.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.entity.ItemData;
import com.turing.usdtpay.entity.TeamData;
import com.turing.usdtpay.mvp.contract.AccountContract;
import com.turing.usdtpay.mvp.contract.TeamContract;
import com.turing.usdtpay.mvp.presenter.TeamPresenter;
import com.turing.usdtpay.mvp.view.BaseTitleView;
import com.turing.usdtpay.utils.DateUtils;
import com.turing.usdtpay.utils.ToastUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @作者：JAY
 * @创建时间：2019/10/29 16:45
 * @描述：
 **/
public class TeamActivity extends Activity implements View.OnClickListener ,TeamContract.View {

    private BaseTitleView mTitleView;
    private LinearLayout linearLayout;
    private TeamContract.Present mPresenter;
    private TextView mRank,mHonor,mTeamNum,mJoin,mReference,mTotal;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_team);
        initView();
        initTitle();
        setPresenter(new TeamPresenter(this));
        initData();
    }

    private void initData() {
        mPresenter.getTeamInfo(this);
    }


    private void initTitle() {
        mTitleView.setTitle("我的团队");
        mTitleView.setLeftShow(true);
        mTitleView.setLeftButtonListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        mTitleView = (BaseTitleView) findViewById(R.id.title);
        linearLayout = (LinearLayout) findViewById(R.id.content_layout);
        mRank = (TextView) findViewById(R.id.tv_rank);
        mHonor = (TextView) findViewById(R.id.tv_honor);
        mTeamNum = (TextView) findViewById(R.id.tv_team_number);
        mJoin = (TextView) findViewById(R.id.tv_join);
        mReference = (TextView) findViewById(R.id.tv_reference);
        mTotal = (TextView) findViewById(R.id.tv_total);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void getSuccess(TeamData data) {
        int rank = data.getRank();
        if (rank == 99){
            mRank.setText("团长");
        }else if (rank == 98){
            mRank.setText("队长");
        }else if (rank == 97){
            mRank.setText("组长");
        }
        mJoin.setText(data.getAdd_num()+"人");
        mHonor.setText("否");
        mTeamNum.setText(data.getTeam_num()+"人");
        mReference.setText(data.getReference()+"人");
        mTotal.setText(data.getTeam_trade_num()+"笔");
        List<ItemData> item = data.getNext_trader();
        for (int i = 0;i< item.size();i++){
            ItemData itemData = item.get(i);
            View itemView = LayoutInflater.from(this).inflate(R.layout.item_team, null);
            TextView mTime = (TextView) itemView.findViewById(R.id.item_time);
            TextView mName = (TextView) itemView.findViewById(R.id.item_name);
            TextView mDuel = (TextView) itemView.findViewById(R.id.item_duel);
            TextView mInvite = (TextView) itemView.findViewById(R.id.item_invite);
            TextView mLevel = (TextView) itemView.findViewById(R.id.item_level);
            TextView mPhone = (TextView) itemView.findViewById(R.id.item_phone);

            mName.setText(itemData.getAct());
            if (itemData.getRank() == 99){
                mLevel.setText("团长");
            }else if (itemData.getRank() == 98){
                mLevel.setText("队长");
            }else if (itemData.getRank() == 97){
                mLevel.setText("组长");
            }else {
                mLevel.setText("");
            }
            mPhone.setText(itemData.getTel());
            mDuel.setText(itemData.getTeam_trader_num()+"笔");
            mInvite.setText(itemData.getTeam_num()+"");
            mTime.setText(DateUtils.dateToStrLong(new Date(itemData.getReg_time()*1000L)));

            linearLayout.addView(itemView);
        }

    }

    @Override
    public void onFail(String msg) {
        ToastUtils.showNormolToast(this,msg);
    }


    @Override
    public void setPresenter(TeamContract.Present presenter) {
        mPresenter = presenter;
    }
}
